/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */

#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__

#include <pin_name.h>

/* 系统 */
//1:1.2V  2:1.0V  3:1.4V
#define SOC_DSP_LDO_LEVEL 3

/* console */
#define CONSOLE_TXD PA4
#define CONSOLE_RXD PA5
#define CONSOLE_TXD_FUNC PA4_UART2_TX
#define CONSOLE_RXD_FUNC PA5_UART2_RX
#define CONSOLE_UART_IDX 1

/* LED */
#define PIN_LED_R LED_PIN_NOT_SET
#define PIN_LED_G PD4
#define PIN_LED_B LED_PIN_NOT_SET
#define LED_FLIP_FLAG 1 /* 低电平亮 */

// #define AW9523_ENABLED
// #define AW9523_RST_PIN  PD1

// #define AW2013_ENABLED
// #define ADD2010_ENABLED

/* RTC */
#define CONFIG_RTC_EN 1

/* 音频 */
#define PIN_PA_MUTE PD0
#define CONFIG_VOL_MAX (88)
#define CONFIG_LEFT_GAIN (-1)  /* 左声道固定 -> PA */
#define CONFIG_RIGHT_GAIN (88) /* 右声道可调 -> REF */
#define CONFIG_MIC_GAIN (18)   /* MIC初始20dB, 该值在20dB基础上增加的dB数 */

/* EQ */
#define APP_EQ_EN 1 /* 软件EQ使能配置 */

/* WiFi */
#define WIFI_SD_CMD PC4
#define WIFI_SD_CMD_FUNC PC4_SD_CMD_CMD
#define WIFI_SD_CLK PC3
#define WIFI_SD_CLK_FUNC PC3_SD_CLK
#define WIFI_SD_DAT0 PC2
#define WIFI_SD_DAT0_FUNC PC2_SD_D0
#define WIFI_SD_DAT1 PC1
#define WIFI_SD_DAT1_FUNC PC1_SD_D1
#define WIFI_SD_DAT2 PC6
#define WIFI_SD_DAT2_FUNC PC6_SD_D2
#define WIFI_SD_DAT3 PC5
#define WIFI_SD_DAT3_FUNC PC5_SD_D3
#define WLAN_ENABLE_PIN PC8
#define WLAN_POWER_PIN PC0

#define PIN_WL_WAKE_HOST PA6
#define PIN_WL_WAKE_HOST_GROUP LPM_DEV_MASK_GENERAL_GPIO2

/* BT */
#define BT_UART_IDX 0
#define BT_UART_TXD PB0
#define BT_UART_RXD PB1
#define BT_UART_TXD_FUNC PB0_UART1_TX
#define BT_UART_RXD_FUNC PB1_UART1_RX
#define BT_DIS_PIN PB8

/* TF Card */
#define TF_SDIO_CMD PC11
#define TF_SDIO_CMD_FUNC PC11_SDIO_CMD
#define TF_SDIO_CLK PC10
#define TF_SDIO_CLK_FUNC PC10_SDIO_CLK
#define TF_SDIO_DAT0 PC9
#define TF_SDIO_DAT0_FUNC PC9_SDIO_D0
#define TF_SDIO_DAT1 PC8
#define TF_SDIO_DAT1_FUNC PC8_SDIO_D1
#define TF_SDIO_SDA PC13
#define TF_SDIO_SDA_FUNC PC13_I2C2_SDA
#define TF_SDIO_SCL PC12
#define TF_SDIO_SCL_FUNC PC12_I2C2_SCL

/* LPM */
#define MAX_LPM_WAKESRC_COUNT 5
/* CONFIG_TEST_LPMVAD: 简单唤醒算法
*  CONFIG_MIT_LPMVAD:  复杂唤醒算法 */
#define CONFIG_TEST_LPMVAD 1
#define LPM_WL_WAKE_HOST_EN 1   /* WIFI 唤醒主控 */
#define LPM_IDLE_CHECK_TIME 30  /* 秒 */
#define LPM_VAD_PIN PA1         /* VAD低功耗唤醒引脚 */
#define LPM_DEEP_WAKEUP_PIN PA1 /* 深度睡眠唤醒引脚 */

/* ADC按键配置 */
#define PIN_ADC_KEY PA1
#define KEY_ADC_VAL1 1751
#define KEY_ADC_VAL2 2311
#define KEY_ADC_VAL3 3051
#define KEY_ADC_VAL4 1376
#define KEY_ADC_VAL5 3587
#define KEY_AD_VAL_OFFSET 100 /* 按键值误差允许 */

#define VAD_ADC_VAL_MAX KEY_ADC_VAL5 + KEY_AD_VAL_OFFSET /* 最大值 + 误差值 */
#define VAD_ADC_VAL_MIN KEY_ADC_VAL4 - KEY_AD_VAL_OFFSET /* 最小值 - 误差值 */

/* 模拟电源按键 */
#define SIMULATED_POWER_KEY 1
#define POWER_KEY_ADC /* 配置则读取模拟电源键adc值，不配置则读取模拟电源键gpio值 */
#define POWER_KEY_PIN PA1
#define POWER_KEY_VAL_MAX 1600
#define POWER_KEY_VAL_MIN 1300

/* SD卡侦测 */
#define CONFIG_SD_CARD_EN 1            /* SD卡使能 */
#define SD_DETECT_PIN     PC7          /* SD卡侦测pin口 GPIO1_16 */
#define SD_DETECT_FUNC    PC7_SDIO_DET /* 该pin口的FUNC */

/* ADC电池侦测 */
#define CONFIG_BATTERY_ADC 0      /* 电池检测 */
#define PIN_BATTERY_ADC -1        /* 电池电量检测，-1：变量模拟一个电压值 */
#define PIN_BATTERY_CHARGE_PIN -1 /* 充电状态检测, -1不检查 */

#define BATTERY_AVG_ROUND 10  /* 电池电量检查的平均次数 */
#define BATTERY_VOLT_LOW 3800 /* 小于该值控制音量输出 */
#define BATTERY_VOLT_MIN 3700 /* 电量小于该值关机 */
#define BATTERY_VOLT_DIFF 100 /* 平均时候删除异常点的阈值 */

/* 可用GPIO列表 */
#define USER_GPIO_LIST_STR                                                                         \
"ID  Name\n \
42  PD4(LED)\n \
46  PD0(PA MUTE)\n \
45  PD1\n \
38  PD7\n \
39  PD8\n \
29  PC12\n \
30  PC13\n \
 2  PA2\n \
59  PB7\n \
60  PB6\n \
61  PB5\n \
62  PB4\n \
"

#endif /* __BOARD_CONFIG_H__ */
